package com.dc.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "t_calibration_water_rust_clean")
public class CalibrationWaterRustCleanEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @JsonIgnore
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "ship_id", columnDefinition = "bigint unsigned NOT NULL")
    private ShipEntity ship;

    @Transient
    private Long shipId;

    @Transient
    private String shipName;

    @Column(name = "area")
    public Double area;        // 面积(m²)

    @Column(name = "power")
    public Double power;       // 耗电量(kwh)   动态

    @Column(name = "power_unit")
    public Double powerUnit;   // 单位耗电(kwh/m)   动态

    @JsonIgnoreProperties(value = { "calibrationWaterRustCleanEntity" })
    @OneToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH}, fetch = FetchType.EAGER)
    @JoinColumn(name = "calibration_water_rust_clean_id", referencedColumnName = "id")
    private List<CalibrationWaterRustCleanChildEntity> inner = new ArrayList<>();

    @Override
    public String toString() {
        return "CalibrationWaterRustCleanEntity{" +
                "id=" + id +
                ", ship=" + ship +
                ", shipId=" + shipId +
                ", shipName='" + shipName + '\'' +
                ", area=" + area +
                ", power=" + power +
                ", powerUnit=" + powerUnit +
                ", inner=" + inner.size() +
                '}';
    }
}
